package com.zjw.controller;


import com.zjw.annotation.domain.ResponseResult;
import com.zjw.annotation.domain.entity.User;
import com.zjw.enums.AppHttpCodeEnum;
import com.zjw.exception.SystemException;
import com.zjw.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/userInfo")
    public ResponseResult getUserInfo() {
        return userService.getUserInfo();
    }

    @PutMapping("/userInfo")
    public ResponseResult putUserInfo(@RequestBody User user) {

        return userService.saveUserInfo(user);
    }

    @PostMapping("/register")
    public ResponseResult register(@RequestBody User user) {
//        数据完整性验证
        if (!StringUtils.hasText(user.getUserName())
                || !StringUtils.hasText(user.getNickName())
                || !StringUtils.hasText(user.getEmail())
                || !StringUtils.hasText(user.getPassword())) {
            throw new SystemException(AppHttpCodeEnum.DATA_UNCOMPLETED);
        }
        return userService.register(user);
    }
}
